package com.departmentstore.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Set;

@Data
@Entity
@Table(name = "department")
public class Department {
    @Id
    @Column(name = "department_id", length = 10)
    @NotBlank(message = "部门ID不能为空")
    @Size(min = 1, max = 10, message = "部门ID长度必须在1-10之间")
    private String departmentId;

    @Column(name = "name", length = 50)
    @NotBlank(message = "部门名称不能为空")
    @Size(min = 1, max = 50, message = "部门名称长度必须在1-50之间")
    private String name;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "manager_id", unique = true, nullable = true)
    @JsonIgnore
    private Employee manager;

    @OneToMany(mappedBy = "department", fetch = FetchType.LAZY)
    @JsonIgnore
    private Set<Employee> employees;

    @OneToMany(mappedBy = "department", fetch = FetchType.LAZY)
    @JsonIgnore
    private Set<DepartmentProduct> departmentProducts;
} 